<?php


class Blackbird_ContactFormController extends Zend_Controller_Action
{
	function indexAction()
	{
		$request = $this->getRequest();
		$form = new Blackbird_Form_ContactForm_Index();
		if ($request->isPost() && $form->isValid($request->getPost()))
		{
			$values = $form->getValues();
			$message = $values['firstname'] . ' ' . $values['lastname'] . "\n\n"
				. $values['message'];

			$mail = new Zend_Mail();
			$mail->setBodyText($message, 'UTF-8');
			$mail->setFrom($values['email'], $values['firstname']);
			$mail->addTo($this->_getParam('to'));
			$mail->setSubject($this->_getParam('subject'));
			$mail->send();

			return $this->_redirect(BASE_URL . '/contact/sent', array('code' => 303));
		}
		$this->view->form = $form;
	}

	function sentAction()
	{
	}

	function routeAction()
	{
		$slugs = $this->_getParam('slugs');
		$this->_forward($slugs[1]);
	}
}

